﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Windows.Interop;
using System.Threading;
using System.Windows.Media.Animation;
using System.Text.RegularExpressions;

namespace JustPlus
{
    /// <summary>
    /// PlayerPanel.xaml 的交互逻辑
    /// </summary>
    public partial class PlayerPanel : UserControl
    {
        private float sopacity = 0.6f;
        public static Brush bkbrush;//存放stackpanel的背景，当鼠标移入菜单项的时候，需要此背景！
        public static double volum;//存放音量值 
        private Image[] ImageCell;
        private DispatcherTimer tm = new DispatcherTimer();
        private DispatcherTimer labeltm = new DispatcherTimer();
        public GetSongList getsong = new GetSongList();
        private MainWindow mwnd = (MainWindow)Application.Current.MainWindow;
        public static int picno = 0;//自动换背景，背景图片编号

        public PlayerPanel()
        {
            InitializeComponent();
            ImageCell = new Image[15] { image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, image11, image12, image14, image15, image16 };
            SetOpacity(0.0f);

            HasLogined();

            //根据设置项设置以下参数
            slider1.Value = Properties.Settings.Default.DefaultVolume * 10;

            if (Properties.Settings.Default.RememberChannel == true)
            {
                if ((Properties.Settings.Default.CloseCate == 2) && !LoginPanel.HasLoginOn)
                {
                    GetSongList.currentchannel = new Channel(0, 1, "华语");
                    GetSongList.lastchannel = null;
                }
                else
                {
                    GetSongList.currentchannel = new Channel(Properties.Settings.Default.CloseCate, Properties.Settings.Default.CloseNo, Properties.Settings.Default.CloseName);
                    GetSongList.lastchannel = null;
                }
            }
            else
            {
                GetSongList.currentchannel = new Channel(0, 1, "华语");
                GetSongList.lastchannel = null;
            }

            if (Properties.Settings.Default.OpenAero == true)
                mwnd.Background = new SolidColorBrush(Colors.Transparent);
            else
            {
                if (Properties.Settings.Default.AutoChangeBKGround == true)
                {
                    picno = Properties.Settings.Default.BKGroundNo;
                    mwnd.bkimage.ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/JustPlus;component/Images/background"
                    + picno.ToString() + @".jpg", UriKind.Absolute));
                }
                else
                {
                    mwnd.bkimage.ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/JustPlus;component/Images/background0.jpg"
                                   , UriKind.Absolute));
                }
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    getsong.NextCompleted += new GetSongList.NextCompletedEventHandler(NextCompleted);
                    getsong.FailLoaded += new GetSongList.FailLoadedEventHandler(FailLoaded);
                    getsong.Next(true);
                }));
                
                if (UpdatePanel.CheckUpdate())
                {
                    MainWindow.notifyIcon.ShowBalloonTip(3000, "更新提示", "软件有更新，请点击菜单中的更新按钮或快捷工具栏进行更新！", System.Windows.Forms.ToolTipIcon.Info);
                }
            }));
        }

        //判断服务器端是否已登录
        public static void HasLogined()
        {
            //ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
            {
                string loginresult = new ConnectionBase().Get(@"http://douban.fm/");
                if (!string.IsNullOrEmpty(loginresult))
                {
                    Match match = Regex.Match(loginresult, @"var\s*globalConfig\s*=\s*{\s*uid\s*:\s*'(\d*)'", RegexOptions.IgnoreCase);
                    string s = match.Groups[1].Value;
                    if (string.IsNullOrEmpty(s))
                        LoginPanel.HasLoginOn = false;
                    else
                        LoginPanel.HasLoginOn = true;
                }
                else
                {
                    LoginPanel.HasLoginOn = false;
                }

            }
            //));
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (Image image in ImageCell)
            {
                image.MouseEnter += new MouseEventHandler(Elem_MouseEnter);
                image.MouseLeave += new MouseEventHandler(Elem_MouseLeave);
            }
            if (LoginPanel.HasLoginOn)
            {
                image6.IsEnabled = true;
                //image6.ToolTip = "喜欢";
            }
            else
            {
                image6.IsEnabled = false;
                image6.ToolTip = "请先登录！";
            }
            if (GetSongList.currentchannel.cate != 2)
            {
                image7.IsEnabled = false;
                image7.ToolTip = "仅私人频道可用！";
            }
            else
            {
                image7.IsEnabled = true;
                image7.ToolTip = "不再播放";
            }
            mwnd.UnlikeThumbNail.IsEnabled = image7.IsEnabled;
            mwnd.UnlikeThumbNail.Description = image7.ToolTip.ToString();
            if (mwnd.stackPanel1.Children.Count == 1 && mwnd.Width < 400)
            {
                MiniPanel minipanel = (MiniPanel)mwnd.stackPanel1.Children[0];
                minipanel.image5.IsEnabled = image7.IsEnabled;
                minipanel.image5.ToolTip = image7.ToolTip;
            }
        }

        //获取到歌曲后设置UI界面
        private void NextCompleted(object sender, Song currentsong)
        {
            //Ele_Loaded();
            Dispatcher.BeginInvoke(new Action(() =>
            {
                label6.Opacity = 0;

                label1.Content = currentsong.artist;
                label2.Content = @"<" + currentsong.albumtitle + @">" + " " + currentsong.public_time;
                label3.Content = currentsong.title;

                if (!SearchPanel.CanFollowMusician(currentsong.artist) && stackPanel1.Children.Count ==2)
                    stackPanel1.Children.Remove(image14);
                else if (stackPanel1.Children.Count == 1)
                    stackPanel1.Children.Add(image14);
                if (!SearchPanel.CanFollowAlbum(currentsong.albumtitle) && stackPanel2.Children.Count == 2)
                    stackPanel2.Children.Remove(image15);
                else if (stackPanel2.Children.Count == 1)
                    stackPanel2.Children.Add(image15);
                if (!SearchPanel.CanFollowMV(currentsong.title, currentsong.artist) && stackPanel3.Children.Count == 2)
                    stackPanel3.Children.Remove(image16);
                else if (stackPanel3.Children.Count == 1)
                    stackPanel3.Children.Add(image16);

                //设置任务栏
                mwnd.Title = GetSongList.currentchannel.channelName + "MHz--" + currentsong.artist + "--" + currentsong.title;
                //设置托盘图标标题，文本长度必须小于65个字符
                if (mwnd.Title.Length >= 64)
                    mwnd.Title = mwnd.Title.Substring(0, 63);
                MainWindow.notifyIcon.Text = mwnd.Title;

                if (currentsong.like == "1")
                {
                    image6.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/like.png", UriKind.Relative));
                    image6.Tag = @"like.png";
                    if(image6.IsEnabled)
                        image6.ToolTip = "取消喜欢";
                    //改变任务栏按钮状态
                    mwnd.LikeThumbNail.Description = image6.ToolTip.ToString();
                    mwnd.LikeThumbNail.ImageSource = (ImageSource)mwnd.Resources["LikeThumbNailImage"];
                }
                else
                {
                    image6.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/favourite.png", UriKind.Relative));
                    image6.Tag = @"favourite.png";
                    if (image6.IsEnabled)
                        image6.ToolTip = "喜欢";

                    mwnd.LikeThumbNail.Description = image6.ToolTip.ToString();
                    mwnd.LikeThumbNail.ImageSource = (ImageSource)mwnd.Resources["FavThumbNailImage"];
                }
                //MainWindow mwnd = (MainWindow)Application.Current.MainWindow;
                mwnd.stackPanel2.Background = new ImageBrush(new BitmapImage(new Uri(currentsong.picture.Replace(@"mpic", @"lpic"), UriKind.Absolute)));
                bkbrush = mwnd.stackPanel2.Background;

                //设置Mini模式
                if (mwnd.stackPanel1.Children.Count == 1 && mwnd.Width < 400)
                {
                    MiniPanel minipanel = (MiniPanel)mwnd.stackPanel1.Children[0];
                    minipanel.image1.Source = new BitmapImage(new Uri(currentsong.picture.Replace(@"mpic", @"lpic"), UriKind.Absolute));
                    minipanel.image4.Source= image6.Source;
                    minipanel.image4.ToolTip = image6.ToolTip;
                    minipanel.label1.Content = mwnd.Title;
                }

                mediaElement1.Source = new Uri(currentsong.url, UriKind.Absolute);
                mediaElement1.Play();
            }));
        }

        private void FailLoaded()
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                label6.Opacity = 1.0;
                label6.Content = @"加载失败，请检查网络或者点击频道重试！";
                //启动定时器，5秒钟后label6消失
                labeltm.Tick += new EventHandler(labeltm_Tick);
                labeltm.Interval = TimeSpan.FromSeconds(5);
                labeltm.Start();
            }));
        }

        private void labeltm_Tick(object sender, EventArgs e)
        {
            label6.Opacity = 0;
            labeltm.Stop();
        }

        //歌曲加载完毕之前，按钮不能使用
        private void Ele_PreLoad()
        {
            for (int i = 3; i <= 11; i++)
            {
                ImageCell[i].IsEnabled = false;
            }
            slider1.IsEnabled = false;
        }

        private void Ele_Loaded()
        {
            for (int i = 3; i <= 11; i++)
            {
                ImageCell[i].IsEnabled = true;
            }
            slider1.IsEnabled = true;
        }

        //设置鼠标进入图片的效果
        private void Elem_MouseEnter(object sender, MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Opacity = 1.0f;
            for (int i = 0; i <= 6; i++)
            {
                if (ImageCell[i] == image)
                {
                    BlurEffect newBlurEffect = new BlurEffect();
                    newBlurEffect.Radius = 3;
                    image.Effect = newBlurEffect;
                }
            }
            
        }

        private void Elem_MouseLeave(object sender, MouseEventArgs e)
        {
            Image image = sender as Image;
            if (image != image8)
                image.Opacity = sopacity;
            else
                image.Opacity = 1.0;
            image.Effect = null;
        }

        public void SetOpacity(float opacity)
        {
            foreach (Image image in ImageCell)
                image.Opacity = opacity;
            slider1.Opacity = opacity;
        }

        private void Grid_MouseEnter(object sender, MouseEventArgs e)
        {
            SetOpacity(sopacity);
        }

        private void Grid_MouseLeave(object sender, MouseEventArgs e)
        {
            Point pt = e.GetPosition(this);
            if (pt.X < 0 && pt.Y < 0.1)
                return;
            SetOpacity(0.0f);
        }

        //关闭
        public void image3_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //保存变量
            lock (this)
            {
                //Properties.Settings.Default.LastLoginState = LoginPanel.HasLoginOn;
                //Properties.Settings.Default.CloseChannel = GetSongList.currentchannel;
                Properties.Settings.Default.CloseCate = GetSongList.currentchannel.cate;
                Properties.Settings.Default.CloseNo = GetSongList.currentchannel.channelNo;
                Properties.Settings.Default.CloseName = GetSongList.currentchannel.channelName;
                Properties.Settings.Default.Save();

                if (!LoginPanel.AutoLogin)
                {
                    //清空Cookies
                    ConnectionBase.cc = new System.Net.CookieContainer(1000, 1000, 100000);
                    ConnectionBase.SaveCookies();
                }
            }
            //if (e.ButtonState == MouseButtonState.Pressed)
            {
                MainWindow.notifyIcon.Dispose();
                Application.Current.Shutdown();
            }
        }

        //最小化
        private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            mwnd.WindowState = WindowState.Minimized;
        }

        //Mini模式
        private void image2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //mwnd.Background = new SolidColorBrush(Colors.Transparent);
            mwnd.Topmost = true;
            mwnd.Left = SystemParameters.WorkArea.Width - 210;
            mwnd.Top = 10;
            if (Properties.Settings.Default.MiniShowInTask)
            {
                mwnd.ShowInTaskbar = true;
                mwnd.taskbar1.ThumbnailClipMargin = new Thickness(0, 0, 40, 75);
            }
            else
            {
                mwnd.ShowInTaskbar = false;
            }
            mwnd.stackPanel1.Children.Clear();
            mwnd.Height = 220;
            mwnd.Width = 200;
            MiniPanel minipanel = new MiniPanel();
            mwnd.stackPanel1.Children.Add(minipanel);
            ThreadPool.QueueUserWorkItem(new WaitCallback((state)=>
            {
                Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (GetSongList.currentsong != null)
                            minipanel.image1.Source = new BitmapImage(new Uri(GetSongList.currentsong.picture, UriKind.Absolute));
                        minipanel.image2.Source = image4.Source;
                        minipanel.image2.ToolTip = image4.ToolTip;
                        minipanel.image4.ToolTip = image6.ToolTip;
                        minipanel.label1.Content = mwnd.Title;
                        if (image6.Tag.ToString() == @"like.png")
                        {
                            minipanel.image4.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/like.png", UriKind.Relative));
                        }
                        minipanel.image5.IsEnabled = image7.IsEnabled;
                        minipanel.image2.MouseLeftButtonDown += new MouseButtonEventHandler(image4_MouseLeftButtonDown);
                        minipanel.image3.MouseLeftButtonDown += new MouseButtonEventHandler(image5_MouseLeftButtonDown);
                        minipanel.image4.MouseLeftButtonDown += new MouseButtonEventHandler(image6_MouseLeftButtonDown);
                        minipanel.image5.MouseLeftButtonDown += new MouseButtonEventHandler(image7_MouseLeftButtonDown);
                        minipanel.image7.MouseLeftButtonDown += new MouseButtonEventHandler(image3_MouseLeftButtonDown);
                    }));
            }));
        }

        //开始播放歌曲
        private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
        {
            image4.ToolTip = @"暂停";
            if (Properties.Settings.Default.AutoChangeBKGround)
            {
                mwnd.bkimage.ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/JustPlus;component/Images/background"
                                            + picno.ToString() + @".jpg", UriKind.Absolute));
            }
            tm.Tick += new EventHandler(tm_Tick);
            tm.Interval = TimeSpan.FromSeconds(1);
            tm.Start();
        }

        private void tm_Tick(object sender, EventArgs e)
        {
            if (!mediaElement1.NaturalDuration.HasTimeSpan)
            {
                label4.Content = "0:0/0:0";
                return;
            }
            TimeSpan TotalSpan = mediaElement1.NaturalDuration.TimeSpan;
            string totalspan = TotalSpan.Minutes.ToString() + ":" + TotalSpan.Seconds.ToString();
            TimeSpan AfterSpan = mediaElement1.Position;
            label4.Content = AfterSpan.Minutes.ToString() + ":" + AfterSpan.Seconds.ToString() + @"/" + totalspan;
            //有的歌曲加载许久，但是mediaelement误认为在播放导致进度条不断增加...
            if (TimeSpan.Compare(TotalSpan,AfterSpan)==-1)
            {
                label4.Content = "加载中...";
                progressBar1.Value = 0;
                tm.Stop();
                getsong.Next(false);
                return;
            }
            progressBar1.Value = mediaElement1.Position.TotalSeconds / mediaElement1.NaturalDuration.TimeSpan.TotalSeconds * 100;
            MainWindow mwnd = (MainWindow)Application.Current.MainWindow;
            mwnd.taskbar1.ProgressValue = progressBar1.Value/100;
            //设置Mini模式
            lock (this)
            {
                if (mwnd.stackPanel1.Children.Count == 1 && mwnd.Width < 400)
                {
                    MiniPanel minipanel = (MiniPanel)mwnd.stackPanel1.Children[0];
                    minipanel.label2.Content = label4.Content;
                }
            }
            
        }

        //一首歌歌曲，需要加载下一首
        private void mediaElement1_MediaEnded(object sender, RoutedEventArgs e)
        {
            label4.Content = "加载中...";
            progressBar1.Value = 0;
            picno = (picno + 1) % 6;
            tm.Stop();
            getsong.Next(false);
        }

        //暂停
        public void image4_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if ((string)image4.Tag == @"pause.png")
            {
                image4.Tag = @"play.png";
                image4.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/play.png", UriKind.Relative));
                image4.ToolTip = @"播放";
                
                //改变任务栏按钮的状态
                mwnd.PlayThumbNail.Description = @"播放";
                mwnd.PlayThumbNail.ImageSource = (ImageSource)mwnd.Resources["PlayThumbNailImage"];

                mediaElement1.Pause();
            }
            else if ((string)image4.Tag == @"play.png")
            {
                image4.Tag = @"pause.png";
                image4.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/pause.png", UriKind.Relative));
                image4.ToolTip = @"暂停";

                mwnd.PlayThumbNail.Description = @"暂停";
                mwnd.PlayThumbNail.ImageSource = (ImageSource)mwnd.Resources["PauseThumbNailImage"];
                mediaElement1.Play();
            }

            //设置Mini模式
            if (mwnd.stackPanel1.Children.Count == 1 && mwnd.Width < 400)
            {
                MiniPanel minipanel = (MiniPanel)mwnd.stackPanel1.Children[0];
                minipanel.image2.Source = image4.Source;
                minipanel.image2.ToolTip = image4.ToolTip;
            }
        }

        //跳过该曲
        public void image5_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
            {
                Dispatcher.BeginInvoke(new Action(() =>
                    {
                        label4.Content = "加载中...";
                        picno = (picno + 1) % 6;//换背景图片
                        progressBar1.Value = 0;
                        
                        //暂停时跳过歌曲，暂停按钮应该变成播放按钮
                        if ((string)image4.Tag == @"play.png")
                            image4_MouseLeftButtonDown(sender, e);
                    }));
                tm.Stop();
                getsong.Next(true);
            }));
            
            //设置Mini模式
            if (mwnd.stackPanel1.Children.Count == 1 && mwnd.Width < 400)
            {
                MiniPanel minipanel = (MiniPanel)mwnd.stackPanel1.Children[0];
                minipanel.label2.Content = label4.Content;
            }
        }

        //改变音量
        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            //slide控件加载的时候会调用此函数，此时的mediaelement1可能为加载，为null
            if (mediaElement1 == null)
                return;
            mediaElement1.Volume = slider1.Value / 10;
            if (slider1.Value < 0.01)
                mediaElement1.Tag = @"volume0.png";
            else if (slider1.Value < 3)
                mediaElement1.Tag = @"volume1.png";
            else if (slider1.Value < 6.5)
                mediaElement1.Tag = @"volume2.png";
            else
                mediaElement1.Tag = @"volume3.png";
            image9.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/" + mediaElement1.Tag, UriKind.Relative));
        }

        //静音--恢复音量
        private void image9_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (slider1.Value > 0.01)
            {
                volum = slider1.Value;
                slider1.Value = 0;
            }
            else
            {
                slider1.Value = volum;
            }
        }

        //喜欢
        public void image6_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (image6.Tag.ToString() == @"favourite.png")
            {
                image6.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/like.png", UriKind.Relative));
                image6.Tag = @"like.png";
                //改变任务栏按钮的状态
                mwnd.LikeThumbNail.ImageSource = (ImageSource)mwnd.Resources["LikeThumbNailImage"];
                ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
                    {
                        getsong.Like(true);
                    }));
            }
            else if (image6.Tag.ToString() == @"like.png")
            {
                image6.Source = new BitmapImage(new Uri(@"/JustPlus;component/Images/favourite.png", UriKind.Relative));
                image6.Tag = @"favourite.png";

                mwnd.LikeThumbNail.ImageSource = (ImageSource)mwnd.Resources["FavThumbNailImage"];
                picno = (picno + 1) % 6;

                ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
                {
                    getsong.Like(false);
                }));
            }

            //暂停时跳过歌曲，暂停按钮应该变成播放按钮
            if ((string)image4.Tag == @"play.png")
                image4_MouseLeftButtonDown(sender, e);

            //设置Mini模式
            if (mwnd.stackPanel1.Children.Count == 1 && mwnd.Width < 400)
            {
                MiniPanel minipanel = (MiniPanel)mwnd.stackPanel1.Children[0];
                minipanel.image4.Source = image6.Source;
                minipanel.image4.ToolTip = image6.ToolTip;
            }
        }

        private void image6_MouseEnter(object sender, MouseEventArgs e)
        {
            if (image6.IsEnabled && image6.Tag.ToString() == @"like.png")
                image6.ToolTip = "取消喜欢"; 
            else if (image6.IsEnabled && image6.Tag.ToString() == @"favourite.png")
                image6.ToolTip = @"喜欢";
            else if (!image6.IsEnabled)
                image6.ToolTip = @"请先登录！";
            mwnd.LikeThumbNail.Description = image6.ToolTip.ToString();
            //设置Mini模式
            if (mwnd.stackPanel1.Children.Count == 1 && mwnd.Width < 400)
            {
                MiniPanel minipanel = (MiniPanel)mwnd.stackPanel1.Children[0];
                minipanel.image3.ToolTip = image6.ToolTip;
            }
        }

        //垃圾桶
        public void image7_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
                {
                    picno = (picno + 1) % 6;
                    getsong.Ban();
                }));
            //暂停时跳过歌曲，暂停按钮应该编程播放按钮
            if ((string)image4.Tag == @"play.png")
                image4_MouseLeftButtonDown(sender, e);

        }

        //sharecate:0-新浪微博；1-腾讯微博；2-人人网
        private string ShareSongInfo(int sharecate)
        {
            string pubUrl="";
            if (GetSongList.currentsong != null)
            {
                Song currentsong=GetSongList.currentsong;
                string songurl="http://douban.fm/?start=" + currentsong.sid + "g" + currentsong.ssid + "g" + GetSongList.currentchannel.channelNo + "&cid=" + GetSongList.currentchannel.channelNo;
				if (GetSongList.currentchannel.channelNo==0)
					songurl += "&context=" + GenePanel.context;
                string title = @"我在使用@justminus 开发的JustListen音乐电台（http://www.win7soft.com/doucontorl/?post=540）收听来自" +
                    currentsong.artist + "的 " + currentsong.title + " (From" + GetSongList.currentchannel.channelName + "MHz) ";

                Parameters parameters = new Parameters();
                Parameters parameters1 = new Parameters();
                switch (sharecate)
                {
                    case 0:
                        parameters.Add("appkey", "2625351872");
                        parameters.Add("url", songurl);
                        parameters.Add("title", title);
                        parameters.Add("source", "");
                        parameters.Add("sourceurl", "");
                        parameters.Add("content", "utf-8");
                        parameters.Add("relatedUid", "justminus");
                        parameters.Add("pic", currentsong.picture);
                        pubUrl = ConnectionBase.ConstructUrlWithParameters("http://v.t.sina.com.cn/share/share.php", parameters);
                        break;
                    case 1:
                        parameters.Add("url", songurl);
					    parameters.Add("title", title);
					    parameters.Add("site", "http://www.douban.fm");
					    parameters.Add("pic", currentsong.picture);
                        parameters.Add("appkey", "801106958");
                        parameters.Add("assname", "justminus");
					    pubUrl = ConnectionBase.ConstructUrlWithParameters("http://v.t.qq.com/share/share.php", parameters);
					    break;
                    case 2:
                        title = @"我在使用@梁昭(104058986) 开发的JustListen音乐电台（http://www.win7soft.com/doucontorl/?post=540）收听来自" +
                    currentsong.artist + "的 " + currentsong.title + " (From" + GetSongList.currentchannel.channelName + "MHz) ";
                        //parameters.Add("isAjax", "true");
                        parameters.Add("url", songurl);
                        parameters.Add("title", title);
                        pubUrl = ConnectionBase.ConstructUrlWithParameters("http://www.connect.renren.com/share/sharer", parameters);
					    break;
                }
            }
            return pubUrl;
        }

        private void image10_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string pubUrl=ShareSongInfo(0);
            if (pubUrl == "")
                return;
            System.Diagnostics.Process.Start(pubUrl);
        }

        private void image11_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string pubUrl = ShareSongInfo(1);
            if (pubUrl == "")
                return;
            System.Diagnostics.Process.Start(pubUrl);
        }

        private void image12_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string pubUrl = ShareSongInfo(2);
            if (pubUrl == "")
                return;
            System.Diagnostics.Process.Start(pubUrl);
        }

        //收听歌手
        private void image14_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (label1.Content.ToString() == @"JustListen")
                return;
            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
                {
                    GetSongList.currentchannel = new Channel(2, 0, @"搜索音乐");
                    GenePanel.context = SearchPanel.musiciancontext;
                    getsong.Next(true);
                }));
        }

        //收听专辑
        private void image15_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (label2.Content.ToString() == @"与喜欢的音乐不期而遇")
                return;
            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
                {
                    GetSongList.currentchannel = new Channel(2, 0, @"搜索音乐");
                    GenePanel.context = SearchPanel.albumcontext;
                    getsong.Next(true);
                }));
        }

        //观看MV
        private void image16_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //WebBrowser webbrowser = new WebBrowser();
            //webbrowser.Navigate(new Uri(SearchPanel.mvurl, UriKind.RelativeOrAbsolute));
            MVWindow mvwindow = new MVWindow();
            mvwindow.Show();
        }
    }
}